package com.qianchang.microfinance.view.hsrecharge;

import android.annotation.SuppressLint;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.text.Editable;
import android.text.InputType;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.JsPromptResult;
import android.webkit.JsResult;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;

import com.dm.library.http.DMOKHttpUtils;
import com.dm.library.http.HttpParams;
import com.dm.library.http.base.JsonResult;
import com.dm.library.http.callback.RequestCallBack;
import com.dm.library.utils.FormatUtil;
import com.dm.library.utils.ToastUtil;
import com.dm.library.widgets.OneLineEditLinearLayout;
import com.dm.library.widgets.OneLineLinearLayout;
import com.qianchang.microfinance.R;
import com.qianchang.microfinance.bean.HSReChargeDataBean;
import com.qianchang.microfinance.bean.UserLoginInfo;
import com.qianchang.microfinance.global.DMApplication;
import com.qianchang.microfinance.utils.DMConstant;
import com.qianchang.microfinance.view.base.BaseActivity;

import org.json.JSONException;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 版 权: 广西鸿胜科技有限公司
 * 描 述: 提现输入金额页面
 * 修 改 人: chen G L
 * 修改时间: 2018/1/9 16:33
 */

public class HSWithdrawInputActivity extends BaseActivity{

    private String url = "";
    @BindView(R.id.btn_withdraw)
    Button btnWithdraw;
    @BindView(R.id.ole_input_withdraw_amount)
    OneLineEditLinearLayout oleInputWithdrawAmount;
    @BindView(R.id.oll_can_withdraw_amount)
    OneLineLinearLayout ollCanWithdrawAmount;
    @BindView(R.id.money_edit_id)
    EditText moneyEdit;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_withdrawinput_layout);
        ButterKnife.bind(this);
        initView();

    }

    private String money = "";
    @Override
    protected void initView() {
        super.initView();
        setTitleName("现金提现");
        Bundle bundle = getBundle();
        if(bundle != null){
            money = bundle.getString("money");
            ollCanWithdrawAmount.setRightContent(money);
        }else {
            ollCanWithdrawAmount.setRightContent(FormatUtil.numKbPointFormat("0.00") + "");
        }
        moneyEdit.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                String temp = s.toString();
                int posDot = temp.indexOf(".");
                if (posDot <= 0) return;
                if (temp.length() - posDot - 1 > 2)
                {
                    s.delete(posDot + 3, posDot + 4);
                }
            }
        });
    }

    @OnClick(R.id.btn_withdraw)
    public void onViewClicked(View view){
        switch (view.getId()){
            case R.id.btn_withdraw:
                String str = ollCanWithdrawAmount.getRightText().toString();
                String inputMoney = moneyEdit.getText().toString();

                if(inputMoney == null || inputMoney.equals("")){
                    ToastUtil.getInstant().show(getApplicationContext(),"请输入提现金额");
                    return;
                }

                double dstr = new Double(inputMoney).doubleValue();
                double dval = new Double(str).doubleValue();
                if(dstr > dval){
                    ToastUtil.getInstant().show(getApplicationContext(),"提现金额不能大于可提现余额");
                    return;
                }

                Bundle bundle = new Bundle();
                bundle.putString("money",inputMoney);
                startActivity(HSWithdrawActivity.class,bundle,true);

                break;
            default:
                break;
        }
    }
}
